package com.stx.stcp.controller;

import com.github.pagehelper.PageInfo;
import com.stx.stcp.bean.TypeBean;
import com.stx.stcp.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class TypeController {

    @Autowired
    private TypeService typeService;

    @RequestMapping("pri/back/typelist")
    public String pageList(Model model,@RequestParam(defaultValue = "1",value = "pageNum") int pageNum){
        List list = typeService.typeList(pageNum);
        PageInfo<TypeBean> pageInfo = new PageInfo<TypeBean>(list);
        model.addAttribute("pageInfo",pageInfo);
        return "back/type_list";
    }

    @RequestMapping("pri/back/typeinsert")
    public String insert(TypeBean typeBean){
        typeService.insert(typeBean);
        return "back/type_add";
//        return "redircet:/pri/back/typelist";
    }

    @RequestMapping("pri/back/typedelete")
    public String delete(int id){
        typeService.delete(id);
        return "redirect:/pri/back/typelist";
    }

    @RequestMapping("pri/back/typeedit")   //form表单处的地址
    public String selectById(int id,Model model){
        TypeBean typeBean = typeService.selectById(id);
        model.addAttribute("type",typeBean);
        return "back/type_edit";   //跳转的页面
    }

    @RequestMapping("pri/back/typeupdate")
    public String update(TypeBean typeBean){
        typeService.update(typeBean);
        return "redirect:/pri/back/typelist";
    }

}
